package com.aischool.webapp.family;

import java.util.Date;

import com.aischool.routes.RouteMapping;
import com.aischool.service.AiCourseClassService;
import com.aischool.service.AiCoursePlanService;
import com.aischool.service.AiCourseService;
import com.aischool.utils.JsonCodeEnum;
import com.aischool.utils.JsonResult;
import com.jfinal.aop.Inject;

@RouteMapping(url = "/front/family/course")
public class CourseController extends BaseFamilyController {
	@Inject
	AiCoursePlanService aiCoursePlanService;
	@Inject
	AiCourseClassService aiCourseClassService;
	@Inject
	AiCourseService aiCourseService;
	/**
	 * 首页
	 */
	public void index() {
		render(view_path + "/course-view.html");
	}
	
	public void getCoursePlan() {
		// 结果类
		JsonResult jr = new JsonResult();

		int login_class_id = this.getAttrForInt("login_class_id");	
		Date start_date = getDate("startdate");
		Date end_date = getDate("enddate");
		
		Object obj = aiCoursePlanService.getCoursePlan(login_class_id, start_date, end_date);
		
		jr.setDicKV("list_course", obj);
		
		jr.setEnum(JsonCodeEnum.Success);
		renderJson(jr.Dic);
	}
	

	public void detaile() {
		// 结果类
		JsonResult jr = new JsonResult();
		
		int course_id = getParaToInt("id",0);
		if (course_id > 0) {
			Object obj = aiCourseService.getOne(course_id);
			if (obj != null) { 
				jr.setDicKV("course_rd", obj); 
			}
			obj = aiCourseClassService.getClass(course_id);
			if (obj != null) { 
				jr.setDicKV("list_courseclass", obj); 
			}
		}
		
		renderJson(jr.Dic);
	}
}
